﻿using CardMonitor.Model;
using CardMonitor.Utils;
using CardMonitor.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CardMonitor.Pages
{
    /// <summary>
    /// SaleCards.xaml 的交互逻辑
    /// </summary>
    public partial class SaleCards : Page
    {
        private MainWindow mainWindow = null;
        private SynchronizationContext _syncContext = null;
        private List<BillModel> items = new List<BillModel>();
        private ImageBrush imageBrush;

        public SaleCards(List<BillModel> bills, MainWindow _win)
        {
            InitializeComponent();
            _syncContext = SynchronizationContext.Current;

            mainWindow = _win;

            for (int i = 0; i < bills.Count; i++)
            {
                BillModel bill = bills[i];
                if ("0".Equals(bill.Type) || "4".Equals(bill.Type) || "3".Equals(bill.Type))
                {
                    bill.Type = "装车业务";
                    bill.ZxQuantity = (double)bill.Nnum;
                }
                if ("1".Equals(bill.Type) || "5".Equals(bill.Type))
                {
                    bill.Type = "卸车业务";
                }
            }
            items = bills;

            listView.ItemsSource = items;
        }

        private void goIndex(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this).GoBack();
        }

        public void setPersonImage(ImageBrush image)
        {
            this.imageBrush = image;
        }

        /// <summary>
        /// 补卡按钮
        /// </summary>
        /// <param name="sender"> </param>
        /// <param name="e">      </param>
        private void Button_Click_GoReport(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            BillModel item = btn.DataContext as BillModel;
            BkCard buycard = new BkCard(item, mainWindow);
            NavigationService.GetNavigationService(this).Navigate(buycard);
        }
    }
}